//
//  MineViewController.m
//  ITrip
//
//  Created by dlios on 15-5-21.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "MineViewController.h"
#import <SDImageCache.h>
#import <UMFeedback.h>
#import "AboutViewController.h"
#import "TimerCloseViewController.h"

#define USERDEFAULT [NSUserDefaults standardUserDefaults]

@interface MineViewController ()<UITableViewDataSource, UITableViewDelegate>
{
    UITableView *MineTableView;
}
@property(nonatomic, retain) UILabel *label;
@end

@implementation MineViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _WIDTH, _HEIGHT)];
    [self.view addSubview:backgroundImageView];
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *backgroundView = [[UIVisualEffectView alloc] initWithEffect:effect];
    backgroundView.frame = CGRectMake(0, 0, _WIDTH, _HEIGHT);
    [self.view addSubview:backgroundView];
    [backgroundImageView setImage:[UIImage imageNamed:@"bgImage2"]];
    
    
    MineTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.width * 220 / 375, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    MineTableView.delegate = self;
    MineTableView.dataSource = self;
    [self.view addSubview:MineTableView];
    MineTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    MineTableView.backgroundColor = [UIColor clearColor];
    
    UIImageView *titleView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width * 220 / 375)];
    [self.view addSubview:titleView];
    [titleView setImage:[UIImage imageNamed:@"qingting"]];
    MineTableView.scrollEnabled = NO;
}

- (void)viewWillAppear:(BOOL)animated
{
    [[CDSideBarController sharedInstance] dismissMenu];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    if (indexPath.section == 0) {
        cell.textLabel.text = @"清除缓存";
        NSInteger size = [[SDImageCache sharedImageCache] getSize];
        self.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 50)];
        self.label.text = [NSString stringWithFormat:@"%ld MB", size / (1024 * 1024)];
        cell.accessoryView = self.label;
    } else if (indexPath.section == 3) {
        cell.textLabel.text = @"关于我们";
    } else if (indexPath.section == 2) {
        cell.textLabel.text = @"意见反馈";
    } else if (indexPath.section == 1) {
        cell.textLabel.text = @"定时关闭";
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        NSInteger size = [[SDImageCache sharedImageCache] getSize];
        [[SDImageCache sharedImageCache] clearDisk];
        self.label.text = [NSString stringWithFormat:@"%d MB", size / (1024 * 1024)];
        [MineTableView reloadData];
    } else if (indexPath.section == 2) {
        [self presentViewController:[UMFeedback feedbackModalViewController] animated:YES completion:^{
//            [[CDSideBarController sharedInstance] dismissMenu];
        }];
         
    } else if (indexPath.section == 3) {
        AboutViewController *about = [[AboutViewController alloc] init];
        [self presentViewController:about animated:YES completion:^{
//            [[CDSideBarController sharedInstance] dismissMenu];
        }];
    } else if (indexPath.section == 1) {
        //1011007742
//        NSString * appstoreUrlString = @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?mt=8&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software&id=1011007742";
//        
//        NSURL * url = [NSURL URLWithString:appstoreUrlString];
//        
//        if ([[UIApplication sharedApplication] canOpenURL:url])
//        {
//            [[UIApplication sharedApplication] openURL:url];
//        }
//        else
//        {
//            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"进入AppStore失败" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//            [alert show];
//        }
        TimerCloseViewController *timer = [[TimerCloseViewController alloc] init];
        [self presentViewController:timer animated:YES completion:^{
//            [[CDSideBarController sharedInstance] dismissMenu];
        }];
        
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor clearColor];
    return view;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 4) {
        return 600;
    }
    if (section != 3) {
        return 12;
    }
    return 60;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
